package com.hongxun.project.assets.pPole.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.pPole.mapper.PPoleMapper;
import com.hongxun.project.assets.pPole.domain.PPole;
import com.hongxun.project.assets.pPole.service.IPPoleService;
import com.hongxun.common.utils.text.Convert;

/**
 * 低压杆塔采集 服务层实现
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class PPoleServiceImpl implements IPPoleService {
    @Autowired
    private PPoleMapper pPoleMapper;

    /**
     * 查询低压杆塔采集信息
     *
     * @param id 低压杆塔采集ID
     * @return 低压杆塔采集信息
     */
    @Override
    public PPole selectPPoleById(String id, String taskId) {
        return pPoleMapper.selectPPoleById(id, taskId);
    }

    @Override
    public PPole selectPPoleByIdForState(String id, String taskId) {
        return pPoleMapper.selectPPoleByIdForState(id, taskId);
    }

    /**
     * 查询低压杆塔采集列表
     *
     * @param pPole 低压杆塔采集信息
     * @return 低压杆塔采集集合
     */
    @Override
    public List<PPole> selectPPoleList(PPole pPole) {
        return pPoleMapper.selectPPoleList(pPole);
    }

    /**
     * 新增低压杆塔采集
     *
     * @param pPole 低压杆塔采集信息
     * @return 结果
     */
    @Override
    public int insertPPole(PPole pPole) {
        pPole.setId(UUID.randomUUID().toString());
        return pPoleMapper.insertPPole(pPole);
    }

    /**
     * 修改低压杆塔采集
     *
     * @param pPole 低压杆塔采集信息
     * @return 结果
     */
    @Override
    public int updatePPole(PPole pPole) {
        return pPoleMapper.updatePPole(pPole);
    }

    /**
     * 删除低压杆塔采集对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePPoleByIds(String ids) {
        return pPoleMapper.deletePPoleByIds(Convert.toStrArray(ids));
    }

    @Override
    public int deletePPoleByIdsAndTaskIds(String ids, String taskIds) {
        return pPoleMapper.deletePPoleByIdsAndTaskIds(Convert.toStrArray(ids), Convert.toStrArray(taskIds));
    }


    @Override
    public void insertOrReplaceOrDelete(List<PPole> entities) {
        for (PPole d : entities) {
//			if (d.getDatastate().equals("删除")) {
//				pPoleMapper.deletePPoleByIdsAndTaskIds(Convert.toStrArray(d.getId()) , Convert.toStrArray(d.getTaskId()));
//			} else {
            PPole pPole = pPoleMapper.selectPPoleById(d.getId(), d.getTaskId());
            if (pPole == null) {
                pPoleMapper.insertPPole(d);
            } else {
                pPoleMapper.updatePPole(d);
//				}
            }
        }
    }

}
